import { ref, watch } from "vue";

const RulesCheck = ({ rules, modelValue }) => {
	const iserr = ref(false);

	// 监听数据
	watch(modelValue, (modelValue) => {
		check(modelValue);

		console.log(iserr.value);
	});

	const check = (modelValue) => {
		if (rules) {
			if (rules.includes("required")) {
				// 检查是否必填项是否存在
				if (!modelValue || modelValue === "" || modelValue === null) {
					iserr.value = true;
				} else {
					iserr.value = false;
				}
			}
		}
	};

	return {
		iserr,
	};
};

export default RulesCheck;
